<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {

											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											//alert(row[0]['describ']+row[0]['codeTypeName']);
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												window.open( "<c:url value='/jsp/openIndexSun.jsp?url=/cashier/preUpdateCashierFood.do'/>"
																		+ "?foodId="
																		+ row[0]["foodId"]
																		,
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");

												$('#' + listDisplayEId)
														.datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {

											var row = $('#' + listDisplayEId).datagrid('getSelections');
											if (row.length == 0) { 
												$.messager.alert('提示', '请选择一条记录操作！', 'info');
												return;
											} else {
												var str = "foodId=" + row[0]['foodId'];
												$.messager.confirm( '提示', '是否删除该条记录？',
																function(r) {
																	if (r) {
																		$ .ajax({
																					type : 'post',
																					url : "<c:url value='/cashier/deleteFoodCashier.do'/>",
																					data : str,
																					dataType : "json",//设置查询参数及提交路径
																					success : function(
																							data) {
																						if (data.success) {
																							$.messager
																									.alert( "提示", "删除成功！", 'info');
																							$( '#' + listDisplayEId).datagrid('reload');
																						} else {
																							$.messager.alert( "提示", data.msg, 'warning');
																						}
																					},
																					error : function() {
																						$.messager .alert(
																										"错误",
																										"系统错误，请联系管理员！",
																										'error');
																					}
																				});
																	}
																	$(
																			'#'
																					+ listDisplayEId)
																			.datagrid(
																					'reload');
																});
											}

										}

									}
									 ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioRole' />";
	}
	function formatterPicture(value, row, index, field) {
		if(row['is_active']==1){
	        return "无";
		}else{
	        return "<img style='width: 100px;height: 100px;' src=\"<c:url value='/jsp/ui/mid/"+row["foodId"]+".jpg'/>\"/>";

		}
    }
	function formatterDelete(value, row, index, field) {
		if (value == "1") {
	        return "已删除";
	    } else if (value == "0") {
	        return "正常";
	    } 
    }
	 function cellStylerDelete(value, row, index) {
		 if(row['is_active']==1){
			 return 'background-color:red;';
		 }
	 }
	
</script>
</head>

<body>
	<table id="listDisplay" title="商品列表" singleSelect=true
		iconCls="icon-list" idField="id"
		url="<c:url value="/cashier/findFoodCashier.do"/>"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="true" pageSize="10"
		pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
			<tr>
				<th field="radioRole" width="25" align="center" styler="cellStylerDelete"
					formatter="formatRadio"></th>
				<th field="foodId" width="80" sortable="true" styler="cellStylerDelete">ID</th>
				<th field="foodName" width="120" sortable="true" editor="text" styler="cellStylerDelete">
					商品名称</th>
				<th field="foodValue" width="100" sortable="true" editor="text" styler="cellStylerDelete">
					商品出售价格</th>
				<th field="foodType" width="100" sortable="true" hidden=true styler="cellStylerDelete">种类</th>
				<th field="foodTypeName" width="140" sortable="true" editor="text" styler="cellStylerDelete">种类名称</th>
				<th field="foodPicture" width="140" sortable="true" editor="text" formatter='formatterPicture' styler="cellStylerDelete" >图片</th>
				<th field="is_active" width="140" sortable="true" editor="text" formatter='formatterDelete' styler="cellStylerDelete" >是否删除</th>
				
			</tr>
		</thead>
	</table>
</body>
</html>